﻿Namespace Catalog
    Public Class Format
        Public Property Id As Integer
        Public Property Position As Integer
        Public Property IsFree As Boolean
        Public Property Description As String
        Public Property Price As Price
        Public Property [AudioFormat] As AudioFormat

        Public Shared Function FromBPObject(frmt As BPOFormat) As Format
            If frmt Is Nothing Then Return Nothing
            Dim newFormat As New Format()

            newFormat.Id = frmt.id
            newFormat.Position = frmt.position
            newFormat.IsFree = frmt.isFree
            newFormat.Description = frmt.description
            newFormat.Price = Price.FromBPObject(frmt.price)

            Return newFormat
        End Function

        Public Shared Function FromBPObject(frmt As KeyValuePair(Of String, BPOFormat)) As Format
            Dim newFormat As Format = Format.FromBPObject(frmt.Value)

            Select Case frmt.Key.ToLower
                Case "mp3"
                    newFormat.[AudioFormat] = AudioFormat.Mp3
                Case "m4a"
                    newFormat.[AudioFormat] = AudioFormat.M4a
                Case "wav"
                    newFormat.[AudioFormat] = AudioFormat.Wav
                Case "zip"
                    newFormat.[AudioFormat] = AudioFormat.Zip
                Case "full download"
                    newFormat.[AudioFormat] = AudioFormat.FullDownload
                Case "apple loops"
                    newFormat.[AudioFormat] = AudioFormat.AppleLoops
                Case "rex"
                    newFormat.[AudioFormat] = AudioFormat.Rex
                Case "synth presets"
                    newFormat.[AudioFormat] = AudioFormat.SynthPresets
                Case "sampler patches"
                    newFormat.[AudioFormat] = AudioFormat.SamplerPatches
                Case "reason refill"
                    newFormat.[AudioFormat] = AudioFormat.ReasonRefill
                Case "elements"
                    newFormat.[AudioFormat] = AudioFormat.Elements
                Case "s4"
                    newFormat.[AudioFormat] = AudioFormat.S4
                Case "ableton live racks"
                    newFormat.[AudioFormat] = AudioFormat.AbletonLiveRacks
                Case "aiff"
                    newFormat.[AudioFormat] = AudioFormat.Aiff
                Case "mp4"
                    newFormat.[AudioFormat] = AudioFormat.Mp4
            End Select

            Return newFormat
        End Function
    End Class

    Public Enum AudioFormat
        Unknown
        Mp3
        M4a
        Wav
        Zip
        FullDownload
        AppleLoops
        Rex
        SynthPresets
        SamplerPatches
        ReasonRefill
        Elements
        S4
        AbletonLiveRacks
        Aiff
        Mp4
    End Enum
End Namespace